import axios from 'axios'

/*
export function someAction (context) {
}
*/
export async function login ({ commit }, form) {
  const response = await axios.post('api/login/', form)
  // 检查结果 如果错误的话抛出异常
  const user = response.data
  commit('LOGIN', user)
  return user
}

export async function logout ({ commit }) {
  commit('LOGOUT')
}

export function validate ({ validate, commit, getters }) {
  if (getters.isLogined) {
    // 如果已经登陆了 就要设置请求头
    commit('LOGIN', getters.getUser)
  }
}
